/* keymgmt.h - headers for keymgmt.c 
*/

#include "idea.h" /* Declaration of IdeaCfbContext */

void mfwrite_trust(MemFile *f, byte trustbyte);

int merge_key_to_ringfile(char *keyfile, char *ringfile, long fp, int packetlength, long keylen);

/* Edit the userid and/or pass phrase for an RSA key pair, and put them	back
   into the ring files */
int dokeyedit(char *mcguffin, char *ringfile, byte ideakey[16]);

/* Copy the first entry in key ring that has mcguffin string in userid and
   put it into keyfile */
int extract_from_keyring (long keySerial, char *keyfile);

/* Lists all entries in keyring that have mcguffin string in userid */
int view_keyring(char *mcguffin, char *ringfile,
		 boolean show_signatures, boolean show_hashes);

/* options: */
#define	CHECK_ALL	0	/* Check all signatures */
#define CHECK_NEW	1	/* Only check new signatures */

/* Write message prefix keyID to a file */
void writekeyID(unitptr n, FILE *f);

/* Extract public key corresponding to keyID or userid from keyfile */
int getpublickey(int flags, MemFile *keyfile, long keySerial, long *_file_position,
	int *_pktlen, byte * timestamp, char * userid, unitptr n, unitptr e);

/* flags: */
#define	GPK_GIVEUP	1
#define	GPK_SHOW	2
#define	GPK_NORVK	4
#define	GPK_DISABLED	8
/* Flag used in getsecretkey() only - should it be GSK_? */
/* Prevents use of existing password list. */
#define GPK_ASKPASS	16
#define GPK_SECRET	32	/* We are actually getting a secret key */

/* Extract private key corresponding to keyID or userid from keyfile */
int getsecretkey(int flags, MemFile *keyfile, long keySerial,
	byte * timestamp, char * userid, byte ideakey[16],
	unitptr n, unitptr e, unitptr d, unitptr p, unitptr q, unitptr u);

/* Return true if ctb is one for a key in a keyring */
int is_key_ctb (byte ctb);

/* Read next key packet from file f, return its ctb in *pctb, and advance
 * the file pointer to point beyond the key packet.
 */
short nextkeypacket(MemFile *f, byte *pctb);

/* Read the next key packet from file f, return info about it in the various
 * pointers.  Most pointers can be NULL without breaking it.
 */
short readkeypacket(MemFile *f, struct IdeaCfbContext *cfb, byte *pctb,
	long *keySerial, byte *timestamp, char *userid,
	unitptr n ,unitptr e, unitptr d, unitptr p, unitptr q, unitptr u,
	long *sigKeySerial, byte *keyctrl);

extern int is_compromised(MemFile *f);

int check_key_sig(MemFile *keyfile, long fpkey, int keypktlen, char *keyuserid,
	 MemFile *sigfile, long keySerialSign, unitptr n, unitptr e);
